import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import Goods from "../views/Goods.vue";
import Order from "../views/Order.vue";
import NotFound from "../views/NotFound.vue";

import User from "../views/user/Default.vue";
import UserAdd from "../views/user/Add.vue";
import UserEdit from "../views/user/Edit.vue";
import UserList from "../views/user/List.vue";

Vue.use(VueRouter);

const routes = [
  {
    path:'/',
    redirect:'/home'
  },
  {
    path: "/home",
    name: "Home",
    component: Home
  },
  {
    path: "/goods",
    name: "Goods",
    component: Goods
  },
  {
    path: "/order",
    name: "Order",
    component: Order
  },
  {
    path: "/user",
    name: "User",
    component: User,
    children: [
      // 进入用户管理页面直接跳到用户列表
      {
        path: '',
        redirect: 'list'
    }, {
        path: 'add',
        component: UserAdd
    }, {
        path: 'list',
        component: UserList
    }, {
        /* 动态路由传参 */
        name:'userEdit',
        path: 'edit/:id',
        component: UserEdit
      }]
  },
  {
    path: "/404",
    name: "NotFound",
    component: NotFound
  },
  {
    path:'*',
    redirect:'/404'
  }
];

const router = new VueRouter({
  routes
});

export default router;
